#!/usr/bin/env python  
  
# import rospy  
# from std_msgs.msg import String  
  
# def talker():  
#     pub = rospy.Publisher('chatter', String, queue_size=10)  
#     rospy.init_node('talker', anonymous=True)  
#     rate = rospy.Rate(10) # 10hz  
#     while not rospy.is_shutdown():  
#         hello_str = "hello world %s" % rospy.get_time()  
#         rospy.loginfo(hello_str)  
#         pub.publish(hello_str)  
#         rate.sleep()  
  
# if __name__ == '__main__':  
#     try:  
#         talker()  
#     except rospy.ROSInterruptException:  
#         pass

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node



class WriterNode(Node):
    """
    创建一个作家节点，并在初始化时输出一个话
    """
    def __init__(self,name):
        super().__init__(name)
        self.get_logger().info("大家好，我是%s,我是一名doctor！" % name)


def main(args=None):
    """
    ros2运行该节点的入口函数
    1. 导入库文件
    2. 初始化客户端库
    3. 新建节点
    4. spin循环节点
    5. 关闭客户端库
    """
    rclpy.init(args=args) # 初始化rclpy
    node = WriterNode("li4")  # 新建一个节点
    try:
        rclpy.spin(node)# 保持节点运行，检测是否收到退出指令（Ctrl+C）
    except KeyboardInterrupt:
        pass
    rclpy.shutdown() # 关闭rclpy